﻿using System;
using System.Collections.Generic;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using IFRS.Web;
using IFRS_Global;

public partial class IFRS_WIN18_3V : PageBase
{
    #region === Event ===

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewMenu();
            BindControl();
            BindData();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }
    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN18_1S.aspx");
    }

    #endregion

    #region === Method ===

    private void ViewMenu()
    {
        MenuTitleBar = Resources.ifrsMenu.WIN18_3V;
    }
    private void BindControl()
    {
        ddlColleteralTypeID.SetData(DDL_TYPE.CollateralType, string.Empty, false, true);
        SetControlReadOnly(form_control);
    }
    private void BindData()
    {
        if (Convert.ToString(Request.QueryString["id"]) != string.Empty)
        {
            var id = Convert.ToInt32(Request.QueryString["id"]);
            var dt = new SPR_COSTOFFUND().SEARCH_BYID(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                var list = new List<CostOfFund>();
                ConvertHelper.ConvertDataTableToObject(dt, list);

                txtTransactionDate.Text = list[0].TransactionDate.DateToString();

                rbtJudgementStatement.SelectedValue = list[0].JudgementStatement.IntToString();
                //rbtIsAllColleteral.SelectedValue = list[0].IsAllColleteral ? "1" : "0";
                if (list[0].IsAllColleteral != null)
                    switch (list[0].IsAllColleteral)
                    {
                        case true:
                            rbtIsAllColleteral.SelectedValue = "1";
                            break;
                        case false:
                            rbtIsAllColleteral.SelectedValue = "0";
                            break;
                    }

                if (list[0].ColleteralTypeID != null)
                    ddlColleteralTypeID.SelectedValue = list[0].ColleteralTypeID.IntToString();

                txtCostOfFund.Text = list[0].CostOfFundValue.DecimalToString();
            }
        }
    }

    #endregion
}